<?php 
@session_start();
include "../include/config.php";
include "../include/db.php";
include "../include/funciones.php";

?>

<style>

</style>
<div class="" style="width:95%; margin:0 auto;">

	<form id="form_login" method="POST" >
	
	<table border="0" cellpadding="1" cellspacing="2" width="100%" class="formulario_alta">
	
		<tr class="tr_user">
			<td>
				<b>Mis Reparticiones:</b>
				
			</td>
		</tr>
		<tr class="tr_user">		
			<td>			 
			    <select name="select_mis_reparticiones" id="select_mis_reparticiones" style="width:100%">
					<?php
					//la que es x defaul
					//union
					//las otras					
					$query3 = " SELECT R.id_rep_dep, desc_corta
								FROM vw_agentes A
								JOIN vw_repart R ON(R.id_rep_dep = A.id_rep_dep)
								WHERE legajo = {$_SESSION['id_usuario']}
								UNION
								SELECT R.id_rep_dep, desc_corta
								FROM admin_usuarios_permiso_perfil P
								JOIN vw_repart R ON (P.id_rep_dep = R.id_rep_dep)
								WHERE id_usuario = {$_SESSION['id_usuario']}
								GROUP BY 1"; 
			
					$result3 = mysql_query($query3) or trigger_error(mysql_error());
					// $CANT_REPARTS = mysql_num_rows($result3);

					while ($row3 = mysql_fetch_array($result3, MYSQL_ASSOC)) { 
								//$arr_users[] = $row3['id_rep_dep'];
					?>
						<option value="<?php echo $row3['id_rep_dep'] ?>"><?php echo utf8_encode($row3['desc_corta']); ?></option>
					<?php } ?>  
		
				</select>  			   
			 </td> 
		</tr>
		
	</table>    
	
	<br/>
	<center>
		<input type="button" id="cambiar_rep" value="Cambiar" class="boton" />
		<input type="button" value="Cancelar" class="boton" onclick="ventanaCambiarRepart.close()" />    
	</center>
	
	</form>
	
</div>


<script type="text/javascript">    

	$(document).ready(function(){
		//$('#c_user').focus();
		//SELECT * FROM admin_usuarios_permiso_perfil WHERE id_usuario = 47319
		
		$('#select_mis_reparticiones').val(<?php echo $_SESSION['id_rep_dep_o'] ?>);
    });
	
$(function(){

	$("#cambiar_rep").click(function(){
		// doLogin();	  
		//alert("sfd");			
		
		var id_rep_dep = $('#select_mis_reparticiones').val();
		if(<?php echo $_SESSION['id_rep_dep_o'] ?> == id_rep_dep ){
			showStickySuccessToast("Ud ya se encuentra en esta Reparticion..");
			return;
		}
		
		var sector = $("#select_mis_reparticiones option:selected").text();
		// var desc_perfil = "as";
		
		var html = $.ajax({        
			type: "POST",        
			url: "ajax_php/cambiar_sector.php",         
			data: "id_rep_dep="+id_rep_dep+"&sector="+sector ,        
			async: false,
			success: function(msg){	
					window.onbeforeunload = null; 
					location.reload();
			   },
			error: function (xhr, ajaxOptions, thrownError) {
				alert(xhr.status);
				alert(thrownError);
			  }		   
		}).responseText;   
		
	});
	
	//
	
})


</script>
